<template>
	<view class="content">
		<view class="search-box">
			<view class="search-left-box">
				<uni-search-bar @confirm="search"  v-model="searchValue" @input="input" @cancel="cancel" @clear="clear" placeholder="输入发货编码查询">
				</uni-search-bar>
			</view>
			<view class="search-right-box">
				<uni-datetime-picker returnType="timestamp" type="date" v-model="fahuoDate" @change="changeLog" />
			</view>
		</view>
		<view class="table-box" >
			<view :class="tableIndex==index?'tableChange':'table'" v-for="(item,index) in tableList" :key="index" @click="tableChange(item,index)">
				<text>{{item.title}}</text>
				<view class="border">
				</view>
			</view>
		</view>
		<z-paging ref="paging" v-model="dataList" :default-page-size="row" @onRefresh="onRefresh" @query="getList"
			auto-show-system-loading auto-show-back-to-top>
			<view class="" style="padding: 190rpx 20rpx 20rpx 20rpx;">
		<view class="list-box" v-for="(item,index) in dataList" :key="index">
			<view class="top-box">
				<view class="tiem-box" v-if="item.projectNos">
					订单编号：{{item.projectNos}}
				</view>
				<view class="status-box">
					<view class="item-box">
						{{$tools.dictDispose(yifahuo_status,item.status)}}
					</view>
				</view>
			</view>
			<view class="xian"></view>
			<view class="title-box" v-if="item.nos">
				发货编码：{{item.nos}}
			</view>
			<view class="info-box">
				<view class="info-item" v-if="item.kehuName">
					<view class="info-item-title">
						客户名称
					</view>
					<view class="info-item-text">
						{{item.kehuName}}
					</view>
				</view>
				<view class="info-item" v-if="item.linkman">
					<view class="info-item-title">
						联系人
					</view>
					<view class="info-item-text">
						{{item.linkman}}
					</view>
				</view>
				<view class="info-item" v-if="item.linktel">
					<view class="info-item-title">
						联系电话
					</view>
					<view class="info-item-text">
						{{item.linktel}}
					</view>
				</view>
			</view>
			<view class="text-box" v-if="item.projectNos">
				订单编号：{{item.projectNos}}
			</view>
			<view class="text-box" v-if="item.fahuoDate">
				发货时间：{{item.fahuoDate}}
			</view>
			<view class="text-box" v-if="item.jiaohuoDate">
				交货时间：{{item.jiaohuoDate}}
			</view>
			<view class="text-box" v-if="item.address">
				发货地址：{{item.address}}
			</view>
			<view class="text-box" v-if="item.guobangDun">
				过磅单重量：{{item.guobangDun}}
			</view>
			<view class="text-box" v-if="item.remark">
				备注：{{item.remark}}
			</view>
			<view class="xian"></view>
			<view class="bnt-box">
				<view class="bnt-big-box">
					<!-- <view class="bnt" @click.stop="inputDialogToggle1(item)" v-if="item.status == 1">
						同意
					</view> -->
					<view class="bnt" @click.stop="inputDialogToggle(item,'拒绝')"  v-if="item.status==2">
						拒绝
					</view>
					<view class="bnt" @click.stop="daohuoBnt(item)"  v-if="item.status==2">
						到货回执
					</view>
					<view class="bnt" @click="inputDialogToggle1(item)" v-if="item.status==3 || item.status==0"  v-hasPermi="['develop:LvYifahuo:tongguo']">
						已发货确认
					</view>
					<view class="bnt" @click.stop="goto1(item)">
						上传过磅单
					</view>
					<view class="bnt" @click.stop="goto(item)">
						查看明细
					</view>
				</view>
			</view>
		</view>
		</view>
		</z-paging>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" :title="text" :value="inputValue"
				placeholder="请输入备注" @confirm="dialogInputConfirm"  :before-close="true" @close="close"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import config from '@/config'
	import {
		lvYifahuoList,
		lvYifahuoBohui,
		lvYifahuoShenhetongguo,
		typesBatch
	} from "@/api/system/index"
	const baseUrl = config.baseUrl
	export default {
		data() {
			return {
				inputText:'',
				infoItem:{},
				name: '',
				text: '',
				searchValue: '',
				tableList: [{
						title: '待发货',
						status: 0,
					},
					// {
					// 	title: '已提交待审核',
					// 	status: 1,
					// },
					{
						title: '已发货',
						status: 2,
					},
					{
						title: '弃审',
						status: 3,
					},
					{
						title: '已到货',
						status: 4,
						
					}
				], //table列表
				row: 10,
				tabList: [],
				tableIndex: 1, //当前选择
				dataList: [],
				status:1,
				fahuoDate:'',
				yifahuo_status:''
			}
		},
		onLoad(e) {
			this.tableIndex = e.tableIndex
			this.status = this.tableList[e.tableIndex].status
			this.dictType()
		},
		onShow() {
			
		},
		methods: {
			// 数据字典
			dictType() {
				typesBatch({
					'yifahuo_status' : 'yifahuo_status'
				}).then(res => {
					this.yifahuo_status  = res.data.yifahuo_status
				})
			},
			bindDateChange(e) { // 新增日期选择事件
				// this.daohuoDate = e.target.value
			},
			changeLog(e) {
				console.log('change事件:', e);
				let date = new Date(e);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				// return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
				this.fahuoDate =  year + "-" + month + "-" + day;
				this.$refs.paging.reload()
			},
			close() {
				this.inputValue = '';
				this.$refs.inputDialog.close()
			},
			reload(){
				console.log('重新加载');
				this.$nextTick(()=>{
					this.$refs.paging.reload()
				})
			},
			inputDialogToggle1(item) {
				uni.showModal({
					title: '提示',
					content: '确定审核通过？',
					success :(res)=> {
						if (res.confirm) {
							lvYifahuoShenhetongguo(item.id).then(res=>{
								this.$refs.paging.reload()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			// enterBnt() {
			// 	uni.showModal({
			// 		title: '提示',
			// 		content: '确定已发货了吗？',
			// 		success :(res)=> {
			// 			if (res.confirm) {
			// 				lvYifahuoShenhetongguo(item.id).then(res=>{
			// 					this.$refs.paging.reload()
			// 				})
			// 			} else if (res.cancel) {
			// 				console.log('用户点击取消');
			// 			}
			// 		}
			// 	});
			// },
			dialogInputConfirm(e) {
				this.inputValue = e
				if (!this.inputValue) {
					return this.$modal.msgError("请输入意见！")
				}
				this.infoItem.name = this.inputValue
				uni.showModal({
					title: '提示',
					content: '确定拒绝通过？',
					success :(res)=> {
						if (res.confirm) {
							lvYifahuoBohui(this.infoItem).then(res=>{
								this.$refs.paging.reload()
								this.close()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			inputDialogToggle(item,e) {
				this.infoItem = item
				this.text = e
				this.$refs.inputDialog.open()
			},
			goto(item) {
				uni.navigateTo({
					url:'/pagesA/deliveryAudit/commodity/index?id=' + item.id
				})
			},
			goto1(e) {
				uni.navigateTo({
					url: '/pagesA/deliveryAudit/uploadDohuo/index?info=' + JSON.stringify(e)
				})
			},
			daohuoBnt(e) {
				uni.navigateTo({
					url: '/pagesA/deliveryAudit/uploadHuizi/index?info=' + JSON.stringify(e)
				})
			},
			deleteBnt(e) {
				var add = e
				uni.showModal({
					title: '提示',
					content: '确定删除报工吗？',
					success :(res)=> {
						if (res.confirm) {
							removeUpdate(add.id).then(res=>{
								this.$refs.paging.reload()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 当页面滚动到底部事件被触发
			onReachBottom() {
				// 通知z-paging滚动到底部了，z-paging会进行相应的处理，例如加载更多数据
				this.$refs.paging.pageReachBottom();
			},
			// 下拉刷新被触发
			onRefresh() {
				// 告知z-paging下拉刷新结束，这样才可以开始下一次的下拉刷新
				setTimeout(() => {
					this.$tools.toast('刷新成功～')
				}, 500)
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			getList(pageNum, pageSize) {
				lvYifahuoList({
					pageNum,
					pageSize,
					status :this.status,
					nos:this.searchValue,
					fahuoDate:this.fahuoDate
				}).then(res => {
					this.$refs.paging.complete(res.rows);
					console.log(res, '这是什么')
				})
			},
			tableChange(item, index) {
				this.tableIndex = index
				this.status = item.status
				this.$refs.paging.reload()
			},
			search(res) {
				this.$refs.paging.reload()
			},
			cancel() {
				this.searchValue= ''
				this.$refs.paging.reload()
			}
			
		}

	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-left: 20rpx;
		padding-right: 20rpx;

		.table-box {
			width: 750rpx;
			position: sticky;
			top: 0;
			z-index: 2;
			background: #ffffff;
			display: flex;
			justify-content: space-around;

			.table {
				padding: 23rpx 0;
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;
				display: flex;
				flex-direction: column;
				align-items: center;

				.border {
					margin-top: 10rpx;
					width: 32rpx;
					height: 4rpx;
				}
			}

			.tableChange {
				padding: 23rpx 0;
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
				display: flex;
				flex-direction: column;
				align-items: center;

				.border {
					margin-top: 10rpx;
					width: 32rpx;
					height: 4rpx;
					background: #8295BC;
				}
			}
		}

		.search-box {
			width: 750rpx;
			height: 103rpx;
			background: #FFFFFF;
			z-index: 99;
			display: flex;
			align-items: center;
			.search-left-box {
				width: 50%;
			}
			.search-right-box {
				width: 45%;
			}
		}

		.list-box {
			padding-left: 20rpx;
			padding-right: 20rpx;
			margin-top: 20rpx;
			border-radius: 8rpx;
			background: #FFF;

			.top-box {
				display: flex;
				align-items: center;
				padding: 20rpx 0rpx;

				.tiem-box {
					color: #999;
					font-size: 24rpx;
				}

				.status-box {
					margin-left: auto;
					display: flex;
					align-items: center;

					.item-box {
						padding: 4rpx 12rpx;
						border-radius: 10rpx;
						background: #F5F7FB;
						color: #8295BC;
						font-size: 24rpx;
					}
				}
			}

			.xian {
				width: 662rpx;
				border-bottom: 1px solid #EAEAEA;
			}

			.title-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: bold;
			}

			.info-box {
				display: flex;
				align-items: center;
				border-radius: 8rpx;
				background: #F5F7FB;
				padding-top: 30rpx;
				padding-bottom: 30rpx;

				.info-item {
					flex: 1;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					.info-item-title {
						color: #999;
						font-size: 24rpx;
					}

					.info-item-text {
						margin-top: 8rpx;
						color: #333;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}

			.text-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				color: #999;
				font-size: 24rpx;
			}

			.bnt-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.bnt-big-box {
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.bnt {
						margin-right: 20rpx;
						display: flex;
						align-items: center;
						border-radius: 10rpx;
						background: #F5F7FB;
						padding: 15rpx 30rpx 15rpx 30rpx;
						color: #4D8987;
						font-size: 24rpx;
					}
					.bnt1 {
						margin-right: 20rpx;
						display: flex;
						align-items: center;
						border-radius: 10rpx;
						background: #4D8987;
						padding: 15rpx 30rpx 15rpx 30rpx;
						color: #ffffff;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>